﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleCasino
{
    // GameManager holds all the menus of the game and the current menu that the player interacts with.
    public static class GameManager
    {
        public static int Current { get; private set; }

        public static Menu[] Menus { get; private set; }
        public static Player CurrentPlayer { get; set; }
        public static string Message { get; set; }
        public static void AddMenus(Menu[] menus)
        {
            GameManager.Menus = menus;
        }
        public static void ChangePlayer()
        {
            // Input name with style
            Message = "player changed";
            Style style = new Style(new Point(20, 20), ConsoleColor.White, ConsoleColor.Black);
            Draw.DrawText("Name: ", style);
            string name = Console.ReadLine();
            Draw.DrawText("Sex:", new Style(new Point(20, 30), ConsoleColor.White, ConsoleColor.Black));
            string sex = Console.ReadLine();
            Sex gender = Sex.Male;
            if (sex == "m")
            {
                gender = Sex.Male;
            }
            else if (sex == "f")
            {
                gender = Sex.Female;
            }
            //TODO: If illegal input - not "m" or "f"
            else
            {
                    
            }
            CurrentPlayer = new Player(name, gender);
        }
        // Connect to an event to change the menu. 
        public static void Subscribe(MenuChanger item)
        {
            item.Change += ChangeTheMenu;    
        }
        public static Menu GetCurrent()
        {
            return Menus[Current];
        }
        // TODO: The method to change the menu after an event fired by a MenuChanger class
        public static void ChangeTheMenu(string name)
        {
            Message = "menu changed";
            for (int i = 0; i < Menus.Length; i++)
            {
                if (Menus[i].Name == name)
                {
                    if (i == 1)
                    {
                        Message = "player input";
                    }
                    Current = i;
                    break;
                }
            }            
        }
    }
}
